<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    autoResize: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      chart: null
    }
  },
  watch: {
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions()
    },
    setOptions({ expectedData, actualData } = {}) {
      this.chart.setOption({
        // color:['#5470c6','#9a60b4','#ee6666','#3ba272','#73c0de','#91cc75', '#fac858', '#fc8452', '#ea7ccc'],
        tooltip: {
            trigger: 'item'
          },
          legend: {
          },
          series: [
            {
              name: '人员数量',
              type: 'pie',
              radius: '50%',
              data: [
                { value: 1048, name: 'C1' },
                { value: 735, name: 'C2' },
                { value: 580, name: 'A1' },
                { value: 484, name: 'A2' },
                { value: 300, name: 'A3' }
              ],
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
      })
    }
  }
}
</script>
